<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Using Google Spreadsheets - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.gdata.spreadsheets.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.gdata.spreadsheets.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.gdata.health.html">Using Google Health</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.gdata.html">Zend_Gdata</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.gdata.gapps.html">Using Google Apps Provisioning</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.gdata.spreadsheets" class="section"><div class="info"><h1 class="title">Using Google Spreadsheets</h1></div>
    

    <p class="para">
        The Google Spreadsheets data <acronym class="acronym">API</acronym> allows client applications to view
        and update Spreadsheets content in the form of Google data <acronym class="acronym">API</acronym> feeds.
        Your client application can request a list of a user&#039;s spreadsheets,
        edit or delete content in an existing Spreadsheets worksheet, and
        query the content in an existing Spreadsheets worksheet.
    </p>

    <p class="para">
        See <a href="http://code.google.com/apis/spreadsheets/overview.html" class="link external">&raquo; http://code.google.com/apis/spreadsheets/overview.html</a>
        for more information about the Google Spreadsheets <acronym class="acronym">API</acronym>.
    </p>

    <div class="section" id="zend.gdata.spreadsheets.creating"><div class="info"><h1 class="title">Create a Spreadsheet</h1></div>
        

        <p class="para">
            The Spreadsheets data <acronym class="acronym">API</acronym> does not currently provide a way to
            programmatically create or delete a spreadsheet.
        </p>
    </div>

    <div class="section" id="zend.gdata.spreadsheets.listspreadsheets"><div class="info"><h1 class="title">Get a List of Spreadsheets</h1></div>
        

        <p class="para">
            You can get a list of spreadsheets for a particular user by using
            the  <span class="methodname">getSpreadsheetFeed()</span> method of the Spreadsheets
            service. The service will return a
            <span class="classname">Zend_Gdata_Spreadsheets_SpreadsheetFeed</span> object
            containing a list of spreadsheets associated with the authenticated
            user.
        </p>

        <pre class="programlisting brush: php">
$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$spreadsheetService = new Zend_Gdata_Spreadsheets($client);
$feed = $spreadsheetService-&gt;getSpreadsheetFeed();
</pre>

    </div>

     <div class="section" id="zend.gdata.spreadsheets.listworksheets"><div class="info"><h1 class="title">Get a List of Worksheets</h1></div>
        

        <p class="para">
            A given spreadsheet may contain multiple worksheets. For each
            spreadsheet, there&#039;s a worksheets metafeed listing all the
            worksheets in that spreadsheet.
        </p>

        <p class="para">
            Given the spreadsheet key from the &lt;id&gt; of a
            <span class="classname">Zend_Gdata_Spreadsheets_SpreadsheetEntry</span>
            object you&#039;ve already retrieved, you can fetch a feed
            containing a list of worksheets associated with that spreadsheet.
        </p>

        <pre class="programlisting brush: php">
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query-&gt;setSpreadsheetKey($spreadsheetKey);
$feed = $spreadsheetService-&gt;getWorksheetFeed($query);
</pre>


        <p class="para">
            The resulting <span class="classname">Zend_Gdata_Spreadsheets_WorksheetFeed</span>
            object feed represents the response from the server. Among other
            things, this feed contains a list of
            <span class="classname">Zend_Gdata_Spreadsheets_WorksheetEntry </span>
            objects (<strong class="command">$feed-&gt;entries</strong>), each of which represents a
            single worksheet.
        </p>
    </div>

    <div class="section" id="zend.gdata.spreadsheets.listfeeds"><div class="info"><h1 class="title">Interacting With List-based Feeds</h1></div>
        

        <p class="para">
            A given worksheet generally contains multiple rows, each
            containing multiple cells. You can request data from the
            worksheet either as a list-based feed, in which each entry
            represents a row, or as a cell-based feed, in which each
            entry represents a single cell. For information on cell-based feeds, see <a href="zend.gdata.spreadsheets.html#zend.gdata.spreadsheets.cellfeeds" class="link">Interacting with cell-based
                feeds</a>.
        </p>

        <p class="para">
            The following sections describe how to get a list-based feed,
            add a row to a worksheet, and send queries with various query
            parameters.
        </p>

        <p class="para">
            The list feed makes some assumptions about how the data is laid
            out in the spreadsheet.
        </p>

        <p class="para">
            In particular, the list feed treats the first row of the
            worksheet as a header row; Spreadsheets dynamically creates
            <acronym class="acronym">XML</acronym> elements named after the contents of header-row cells.
            Users who want to provide Gdata feeds should not put any data
            other than column headers in the first row of a worksheet.
        </p>

        <p class="para">
            The list feed contains all rows after the first row up to the
            first blank row. The first blank row terminates the data set.
            If expected data isn&#039;t appearing in a feed, check the worksheet
            manually to see whether there&#039;s an unexpected blank row in the
            middle of the data. In particular, if the second row of the
            spreadsheet is blank, then the list feed will contain no data.
        </p>

        <p class="para">
            A row in a list feed is as many columns wide as the worksheet itself.
        </p>

        <div class="section" id="zend.gdata.spreadsheets.listfeeds.get"><div class="info"><h1 class="title">Get a List-based Feed</h1></div>
            

            <p class="para">
                To retrieve a worksheet&#039;s list feed, use the
                 <span class="methodname">getListFeed()</span> method of the Spreadsheets service.
            </p>

            <pre class="programlisting brush: php">
$query = new Zend_Gdata_Spreadsheets_ListQuery();
$query-&gt;setSpreadsheetKey($spreadsheetKey);
$query-&gt;setWorksheetId($worksheetId);
$listFeed = $spreadsheetService-&gt;getListFeed($query);
</pre>


            <p class="para">
                The resulting <span class="classname">Zend_Gdata_Spreadsheets_ListFeed</span>
                object <var class="varname">$listfeed</var> represents a response from the
                server. Among other things, this feed contains an array of
                <span class="classname">Zend_Gdata_Spreadsheets_ListEntry</span> objects
                (<strong class="command">$listFeed-&gt;entries</strong>), each of which represents
                a single row in a worksheet.
            </p>

            <p class="para">
                Each <span class="classname">Zend_Gdata_Spreadsheets_ListEntry</span> contains an
                array, <span class="property">custom</span>, which contains the data for that
                row. You can extract and display this array:
            </p>

            <pre class="programlisting brush: php">
$rowData = $listFeed-&gt;entries[1]-&gt;getCustom();
foreach($rowData as $customEntry) {
  echo $customEntry-&gt;getColumnName() . &quot; = &quot; . $customEntry-&gt;getText();
}
</pre>


            <p class="para">
                An alternate version of this array, <span class="property">customByName</span>,
                allows direct access to an entry&#039;s cells by name. This is
                convenient when trying to access a specific header:
            </p>

            <pre class="programlisting brush: php">
$customEntry = $listFeed-&gt;entries[1]-&gt;getCustomByName(&#039;my_heading&#039;);
echo $customEntry-&gt;getColumnName() . &quot; = &quot; . $customEntry-&gt;getText();
</pre>

        </div>

        <div class="section" id="zend.gdata.spreadsheets.listfeeds.reverse"><div class="info"><h1 class="title">Reverse-sort Rows</h1></div>
            

            <p class="para">
                By default, rows in the feed appear in the same order as the
                corresponding rows in the GUI; that is, they&#039;re in order by
                row number. To get rows in reverse order, set the reverse
                properties of the <span class="classname">Zend_Gdata_Spreadsheets_ListQuery</span>
                object to <b><tt>TRUE</tt></b>:
            </p>

            <pre class="programlisting brush: php">
$query = new Zend_Gdata_Spreadsheets_ListQuery();
$query-&gt;setSpreadsheetKey($spreadsheetKey);
$query-&gt;setWorksheetId($worksheetId);
$query-&gt;setReverse(&#039;true&#039;);
$listFeed = $spreadsheetService-&gt;getListFeed($query);
</pre>


            <p class="para">
                Note that if you want to order (or reverse sort) by a
                particular column, rather than by position in the worksheet,
                you can set the <span class="property">orderby</span> value of the
                <span class="classname">Zend_Gdata_Spreadsheets_ListQuery</span> object to
                <em class="emphasis">column:&lt;the header of that column&gt;</em>.
            </p>
        </div>

        <div class="section" id="zend.gdata.spreadsheets.listfeeds.sq"><div class="info"><h1 class="title">Send a Structured Query</h1></div>
            

            <p class="para">
                You can set a <span class="classname">Zend_Gdata_Spreadsheets_ListQuery</span>&#039;s
                <span class="property">sq</span> value to produce a feed with entries that meet
                the specified criteria. For example, suppose you have a worksheet
                containing personnel data, in which each row represents
                information about a single person. You wish to retrieve all rows
                in which the person&#039;s name is &quot;John&quot; and the person&#039;s age is over
                25. To do so, you would set <span class="property">sq</span> as follows:
            </p>

            <pre class="programlisting brush: php">
$query = new Zend_Gdata_Spreadsheets_ListQuery();
$query-&gt;setSpreadsheetKey($spreadsheetKey);
$query-&gt;setWorksheetId($worksheetId);
$query-&gt;setSpreadsheetQuery(&#039;name=John and age&gt;25&#039;);
$listFeed = $spreadsheetService-&gt;getListFeed($query);
</pre>

        </div>

        <div class="section" id="zend.gdata.spreadsheets.listfeeds.addrow"><div class="info"><h1 class="title">Add a Row</h1></div>
            

            <p class="para">
                Rows can be added to a spreadsheet by using the
                 <span class="methodname">insertRow()</span> method of the Spreadsheet service.
            </p>

            <pre class="programlisting brush: php">
$insertedListEntry = $spreadsheetService-&gt;insertRow($rowData,
                                                    $spreadsheetKey,
                                                    $worksheetId);
</pre>


            <p class="para">
                The <var class="varname">$rowData</var> parameter contains an array of column
                keys to data values. The method returns a
                <span class="classname">Zend_Gdata_Spreadsheets_SpreadsheetsEntry</span> object
                which represents the inserted row.
            </p>

            <p class="para">
                Spreadsheets inserts the new row immediately after the last row
                that appears in the list-based feed, which is to say
                immediately before the first entirely blank row.
            </p>
        </div>

        <div class="section" id="zend.gdata.spreadsheets.listfeeds.editrow"><div class="info"><h1 class="title">Edit a Row</h1></div>
            

            <p class="para">
                Once a <span class="classname">Zend_Gdata_Spreadsheets_ListEntry</span> object
                is fetched, its rows can be updated by using the
                 <span class="methodname">updateRow()</span> method of the Spreadsheet service.
            </p>

            <pre class="programlisting brush: php">
$updatedListEntry = $spreadsheetService-&gt;updateRow($oldListEntry,
                                                   $newRowData);
</pre>


            <p class="para">
                The <var class="varname">$oldListEntry</var> parameter contains the list entry
                to be updated. <var class="varname">$newRowData</var> contains an array of
                column keys to data values, to be used as the new row data.
                The method returns a
                <span class="classname">Zend_Gdata_Spreadsheets_SpreadsheetsEntry</span> object
                which represents the updated row.
            </p>
        </div>

        <div class="section" id="zend.gdata.spreadsheets.listfeeds.deleterow"><div class="info"><h1 class="title">Delete a Row</h1></div>
            

            <p class="para">
                To delete a row, simply invoke  <span class="methodname">deleteRow()</span> on the
                <span class="classname">Zend_Gdata_Spreadsheets</span> object with the existing
                entry to be deleted:
            </p>

            <pre class="programlisting brush: php">
$spreadsheetService-&gt;deleteRow($listEntry);
</pre>


            <p class="para">
                Alternatively, you can call the  <span class="methodname">delete()</span> method of
                the entry itself:
            </p>

            <pre class="programlisting brush: php">
$listEntry-&gt;delete();
</pre>

        </div>
    </div>

    <div class="section" id="zend.gdata.spreadsheets.cellfeeds"><div class="info"><h1 class="title">Interacting With Cell-based Feeds</h1></div>
        

        <p class="para">
            In a cell-based feed, each entry represents a single cell.
        </p>

        <p class="para">
            Note that we don&#039;t recommend interacting with both a cell-based
            feed and a list-based feed for the same worksheet at the same time.
        </p>

        <div class="section" id="zend.gdata.spreadsheets.cellfeeds.get"><div class="info"><h1 class="title">Get a Cell-based Feed</h1></div>
            

            <p class="para">
                To retrieve a worksheet&#039;s cell feed, use the
                 <span class="methodname">getCellFeed()</span> method of the Spreadsheets service.
            </p>

            <pre class="programlisting brush: php">
$query = new Zend_Gdata_Spreadsheets_CellQuery();
$query-&gt;setSpreadsheetKey($spreadsheetKey);
$query-&gt;setWorksheetId($worksheetId);
$cellFeed = $spreadsheetService-&gt;getCellFeed($query);
</pre>


            <p class="para">
                The resulting <span class="classname">Zend_Gdata_Spreadsheets_CellFeed</span>
                object <var class="varname">$cellFeed</var> represents a response from the
                server. Among other things, this feed contains an array of
                <span class="classname">Zend_Gdata_Spreadsheets_CellEntry</span> objects
                (<strong class="command">$cellFeed&gt;entries</strong>), each of which represents
                a single cell in a worksheet. You can display this information:
            </p>

            <pre class="programlisting brush: php">
foreach($cellFeed as $cellEntry) {
  $row = $cellEntry-&gt;cell-&gt;getRow();
  $col = $cellEntry-&gt;cell-&gt;getColumn();
  $val = $cellEntry-&gt;cell-&gt;getText();
  echo &quot;$row, $col = $val\n&quot;;
}
</pre>

        </div>

        <div class="section" id="zend.gdata.spreadsheets.cellfeeds.cellrangequery"><div class="info"><h1 class="title">Send a Cell Range Query</h1></div>
            

            <p class="para">
                Suppose you wanted to retrieve the cells in the first column
                of a worksheet. You can request a cell feed containing only
                this column as follows:
            </p>

            <pre class="programlisting brush: php">
$query = new Zend_Gdata_Spreadsheets_CellQuery();
$query-&gt;setMinCol(1);
$query-&gt;setMaxCol(1);
$query-&gt;setMinRow(2);
$feed = $spreadsheetService-&gt;getCellsFeed($query);
</pre>


            <p class="para">
                This requests all the data in column 1, starting with row 2.
            </p>
        </div>

        <div class="section" id="zend.gdata.spreadsheets.cellfeeds.updatecell"><div class="info"><h1 class="title">Change Contents of a Cell</h1></div>
            

            <p class="para">
                To modify the contents of a cell, call
                 <span class="methodname">updateCell()</span> with the row, column,
                and new value of the cell.
            </p>

            <pre class="programlisting brush: php">
$updatedCell = $spreadsheetService-&gt;updateCell($row,
                                               $col,
                                               $inputValue,
                                               $spreadsheetKey,
                                               $worksheetId);
</pre>


            <p class="para">
                The new data is placed in the specified cell in the worksheet.
                If the specified cell contains data already, it will be
                overwritten. Note: Use  <span class="methodname">updateCell()</span> to change
                the data in a cell, even if the cell is empty.
            </p>
        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.gdata.health.html">Using Google Health</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.gdata.html">Zend_Gdata</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.gdata.gapps.html">Using Google Apps Provisioning</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.gdata.html">Zend_Gdata</a></li>
  <li><a href="zend.gdata.introduction.html">Introduction</a></li>
  <li><a href="zend.gdata.authsub.html">Authenticating with AuthSub</a></li>
  <li><a href="zend.gdata.books.html">Using the Book Search Data API</a></li>
  <li><a href="zend.gdata.clientlogin.html">Authenticating with ClientLogin</a></li>
  <li><a href="zend.gdata.calendar.html">Using Google Calendar</a></li>
  <li><a href="zend.gdata.docs.html">Using Google Documents List Data API</a></li>
  <li><a href="zend.gdata.health.html">Using Google Health</a></li>
  <li class="active"><a href="zend.gdata.spreadsheets.html">Using Google Spreadsheets</a></li>
  <li><a href="zend.gdata.gapps.html">Using Google Apps Provisioning</a></li>
  <li><a href="zend.gdata.gbase.html">Using Google Base</a></li>
  <li><a href="zend.gdata.photos.html">Using Picasa Web Albums</a></li>
  <li><a href="zend.gdata.youtube.html">Using the YouTube Data API</a></li>
  <li><a href="zend.gdata.exception.html">Catching Gdata Exceptions</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>